
#ifndef MAINHANDLER_H
#define MAINHANDLER_H

#include <BMap>
#include <BCamera>
#include <BLight>
#include <BSphereHandler>
#include <BOctTree>

using namespace BWE;

namespace BWE
{
	struct SceneSet
	{
		BArray<BShapeHolder>	shapes;
		BArray<BNodeHolder>		nodes;
		BArray<BLight*>			lights;
		BArray<BCamera*>		cameras;
	};
	typedef BOctTree<SceneSet>			SceneTree;
	typedef SceneTree::Item				SceneTreeItem;
	typedef SceneTree::ItemArray		SceneTreeItemArray;
	typedef SceneTree::ConstItem		SceneTreeConstItem;
	typedef SceneTree::ConstItemArray	ConstSceneTreeItemArray;
}

class MainHandler : public BSphereHandler
{
public:
	MainHandler();
	~MainHandler();

	void setTargetCamera(BCamera* camera);
	void setTargetScene(BScene* scene);
	void setShapeBoxVisible(bool shapeBoxVisible);
	void setFrustumVisible(bool frustumVisible);
	void setFrustumSpaceVisible(bool frustumSpaceVisible);

protected:
	void slotTargetCameraFresh();
	void slotTargetSceneOptimizedChanged();
	void slotLineChanged(BObject* object, const BValue& value);
	void slotAttached();
	void slotDetached();

protected:
	virtual void paint(BPainter& painter);
	virtual void render(BRender& render);

	virtual bool mousePressEvent(const BMouseEvent& mouseEvent);
	virtual bool mouseReleaseEvent(const BMouseEvent& mouseEvent);
	virtual bool mouseMoveEvent(const BMouseEvent& mouseEvent);

private:
	BLine								_line;
	bool								_shapeBoxVisible;
	bool								_frustumVisible;
	bool								_frustumSpaceVisible;

	BCameraHolder						_targetCamera;
	BSceneHolder						_targetScene;
	BHolder<BVectorArray>				_frustumPoints;
	BHolder<BLightArray>				_enableLights;
	BHolder<BNodeArray>					_visualNodes;
	BHolder<BMap<BShape*, BBox>>		_shapeQueue;
	BHolder<BMap<BShape*, BBox>>		_transShapeQueue;
	BHolder<ConstSceneTreeItemArray>	_constSceneItems;
};

#endif
